<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>管理系统</title>
  <link rel="shortcut icon" href="/static/images/lock.png" type="image/x-icon">
  <link rel="stylesheet" href="/static/css/stylemain.css">
  <link rel="stylesheet" href="/static/layui/css/layui.css">
  
  <link rel="stylesheet" href="/static/layui/css/treeTable.css">
  <link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body class="layui-layout-body">

<script id="pswmodify" type="text/html">
	<form class="layui-form" action="" style="margin-top:20px;width:360px">
		<div class="layui-form-item">
		    <label class="layui-form-label">原密码</label>
		    <div class="layui-input-block">
		      <input type="text" id="oldpsw" name="oldpsw" lay-verify="required" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
	    	<label class="layui-form-label">新密码</label>
		    <div class="layui-input-block">
		      <input type="text" id="newpsw" name="newpsw" lay-verify="required" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">密码确认</label>
		    <div class="layui-input-block">
		      <input type="text" id="repsw" name="repsw" lay-verify="required" autocomplete="off" class="layui-input">
		    </div>
	  	</div>	  	
	</form>
</script>

<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo"><img src="/static/images/prevail.gif" style="height:50px"></div>

    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="/static/images/person.jpg" class="layui-nav-img">
          <span id="top_user"></span>
        </a>
        <dl class="layui-nav-child">
          <dd><a href="#" onclick="us_modify()">修改密码</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a href="" onclick="user_logout()">注销</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test" lay-shrink="all">
      	<li class="layui-nav-item layui-nav-itemed">
          <a class="" style="padding:0 10px;" href="javascript:;"><i class="fa fa-unlock-alt fa-lg" aria-hidden="true"></i>智能锁管理</a>
          <dl class="layui-nav-child">
          	<dd><a class="sm_item" href="#" id="_sm_item_3_1"><i class="fa fa-hand-o-right" aria-hidden="true"></i>锁具管理</a></dd>
          	<dd><a class="sm_item" href="#" id="_sm_item_3_4"><i class="fa fa-hand-o-right" aria-hidden="true"></i>锁具移交管理</a></dd>
          	<dd><a class="sm_item" href="#" id="_sm_item_3_5"><i class="fa fa-hand-o-right" aria-hidden="true"></i>钥匙管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_3_2"><i class="fa fa-hand-o-right" aria-hidden="true"></i>单人任务管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_3_3"><i class="fa fa-hand-o-right" aria-hidden="true"></i>调拨任务管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_3_9"><i class="fa fa-hand-o-right" aria-hidden="true"></i>测试页面</a></dd>            
          </dl>
        </li>
        <li class="layui-nav-item">
          <a style="padding:0 10px;" href="javascript:;"><i class="fa fa-history fa-lg" aria-hidden="true"></i>记录管理</a>
          <dl class="layui-nav-child">
            <dd><a class="sm_item" href="#" id="_sm_item_2_1"><i class="fa fa-hand-o-right" aria-hidden="true"></i>开锁记录</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_2_2"><i class="fa fa-hand-o-right" aria-hidden="true"></i>锁具报废记录</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_2_3"><i class="fa fa-hand-o-right" aria-hidden="true"></i>人员变更记录</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_2_4"><i class="fa fa-hand-o-right" aria-hidden="true"></i>系统记录</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a class="" style="padding:0 10px;" href="javascript:;"><i class="fa fa-cog fa-lg" aria-hidden="true"></i>系统设置</a>
          <dl class="layui-nav-child">
            <dd><a class="sm_item" href="#" id="_sm_item_1_1"><i class="fa fa-hand-o-right" aria-hidden="true"></i>用户管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_1_2"><i class="fa fa-hand-o-right" aria-hidden="true"></i>角色管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_1_3"><i class="fa fa-hand-o-right" aria-hidden="true"></i>机构管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_1_4"><i class="fa fa-hand-o-right" aria-hidden="true"></i>功能管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_1_5"><i class="fa fa-hand-o-right" aria-hidden="true"></i>授权管理</a></dd>
            <dd><a class="sm_item" href="#" id="_sm_item_1_6"><i class="fa fa-hand-o-right" aria-hidden="true"></i>系统参数</a></dd>
            
          </dl>
        </li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 0px 5px;" id="cc_content">
		<div class="layui-tab" lay-filter="main-tabmanager" lay-allowClose="true">
		  <ul class="layui-tab-title">
		    <li class="layui-this">系统介绍</li>

		  </ul>
		  <div class="layui-tab-content" style="height: 100%;overflow-y: hidden;">
		    <div class="layui-tab-item layui-show">1</div>

		  </div>
		</div>
	</div>
  </div>
  
</div>
<div style="width:300px;margin-top:20px;display:none" id="dlgck">
	<div class="layui-form-item">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" id="ckname" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
    	<label class="layui-form-label">密码</label>
	    <div class="layui-input-block">
	      <input type="password" id="ckpassword" class="layui-input">
	    </div>
  	</div>
</div>
<script src="/static/layui/layui.all.js"></script>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/base64.js"></script>
<script>
//JavaScript代码区域
var userSession;
var element;
var iframeH = 0;
layui.use('element', function(){
  	element = layui.element;
  	iframeH = $(window).height() - 130;
});

function tabAdd(id,tabtitle,htmlsrc){
	var exist=$("li[lay-id='"+id+"']").length; //判断是否存在tab
	if(exist==0){
		element.tabAdd('main-tabmanager', {
	        title: tabtitle
	        ,content: '<iframe scrolling="no" frameborder="0" src="' + htmlsrc + '" style="width:100%;height:100%"></iframe>'
	        ,id: id
	    });
	}
	
    element.tabChange('main-tabmanager', id);
    $(".layui-show").css('height',iframeH);
}

$(document).ready(function(){
	$.ajaxSetup({ 
		error: function (XMLHttpRequest, textStatus, errorThrown){
			if(XMLHttpRequest.status==403){
				alert('您没有权限访问此资源或进行此操作');
				return false;
			}
		},  
		complete:function(XMLHttpRequest,textStatus){   
	        var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头,sessionstatus， 
             if(sessionstatus=='timeout'){   
				debugger;
            	 location.reload(); //跳转到登陆页面
             }   
         },
         cache: false
	}); 
	
	init_core();
	
	$('.sm_item').click(function(){
		var flag = $(this).attr("id");
		if(flag == "_sm_item_1_1"){
			tabAdd("usermanager","用户管理","usermanager");
			//load('usermanager.html',"");
		}else if(flag == "_sm_item_1_2"){
			tabAdd("rolemanager","角色管理","rolemanager");
			//load('rolemanager.html',"")
		}else if(flag == "_sm_item_1_3"){
			tabAdd("organization","机构管理","organization");
			//load('organization.html',"")
		}else if(flag == "_sm_item_1_4"){
			load('rightmanager.html',"")
		}else if(flag == "_sm_item_1_5"){
			load('user_right_auth.html',"")
		}else if(flag == "_sm_item_1_6"){
			load('sysconfig.html',"")
		}else if(flag == "_sm_item_2_1"){
			load('openlog.html',"")
			//tabAdd("checklog","开锁日志","checklog.html");
		}else if(flag == "_sm_item_2_2"){
			load('lockofflog.html',"")
			//tabAdd("lockofflog","报废日志","lockofflog.html");
		}else if(flag == "_sm_item_2_3"){
			load('usermanagerlog.html',"")
			//tabAdd("usermanagerlog","用户变更日志","usermanagerlog.html");
		}else if(flag == "_sm_item_2_4"){
			load('usersyslog.html',"")
			//tabAdd("usersyslog","系统日志","usersyslog.html");
		}else if(flag == "_sm_item_3_1"){
			tabAdd("lockmanage","锁具管理","lockmanage");
			//load('lockmanage.html',"")
		}else if(flag == "_sm_item_3_2"){
			tabAdd("lockmission","单人任务","lockmission");
			//load('lockmission.html',"")
		}else if(flag == "_sm_item_3_3"){
			tabAdd("allotmission","调拨任务","allotmission");
			//load('allotmission.html',"")
		}else if(flag == "_sm_item_3_4"){
			tabAdd("locktransfer","锁具移交","locktransfer");
			//load('locktransfer.html',"")
		}else if(flag == "_sm_item_3_5"){
			tabAdd("keymanage","钥匙管理","keymanage");
			//load('keymanage.html',"")
		}else if(flag == "_sm_item_3_9"){
			load('test.html',"")
		}
		
		
	});

});



function user_logout(){
	$.ajax({
		type:"GET",
		contentType: "application/json;charset=UTF-8",
		url: "logout",
		async:false,
     	dataType:"text",
        success: function(msg) {    //数据提交成功时返回数据

        	location.reload();
							
			
        },
        error : function(e){
            alert(e.status);
            alert(e.responseText);
        }

	});
}

function load(url, data){   
    $.ajaxSetup({cache: false });
    $("#cc_content").empty();
    
    $("#cc_content").load(url, function(result,statusTxt,xhr){

    });

}

function init_core(){
	$.ajax({
		type:"GET",
		contentType: "application/json;charset=UTF-8",
		url: "getInitCore",
		async:false,
		//data:"length="+length,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
			userSession = msg;
        	if(msg.status == "1"){
        		if(msg.needupdatepsw == 1){
        			//需要先修改密码
        			//$('#username').textbox('setValue',userSession.username);
        			us_modify();         			
        		}
        		//debugger;
        		$("#top_user").html(msg.username);
        		
            	if(msg.systitle != ""){
            		document.title = msg.systitle;
            	}
        	}else{
        		layer.msg(msg.desc);
        	}  		
			   
        },
        error : function(e){                	
            //alert(e.status);
            //alert(e.responseText);
        }

	});
}

function us_modify(){
	var win = layer.open({
		  type: 1 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "密码修改" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['400px', '300px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: $("#pswmodify").html()     //内容
		  ,btn: ['确定', '取消'] //只是为了演示
		  ,success:function(layero){
			     //var mask = $(".layui-layer-shade");
			     //mask.appendTo(layero.parent());
			}
		,yes: function(index, layero){
		    //按钮【按钮一】的回调
		    	debugger;
		    	sub_modifypsw();
		    	sub_pswclear();
			 	 
		  }
		  ,btn2: function(index, layero){
		    //按钮【按钮二】的回调
		    	sub_pswclear();
		    	//$("#useradd").css('display','none'); 
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
			    //$("#useradd").css('display','none'); 
			    sub_pswclear();
		 }
	});
}

function sub_modifypsw(){
	var password = $('#newpsw').val();
	var oldpassword = $('#oldpsw').val();
	var datastring = '{"oldpassword":"'+ $.base64.encode(oldpassword)  +'","password":"'+ $.base64.encode(password) + '"}';
	
	if($("#oldpsw").val().length < 1){
		layer.msg('请输入密码!');
		return ;
	}
	if($("#newpsw").val() != $("#repsw").val()){
		layer.msg('两次输入密码不一致!');
		return;
	}
	if($("#newpsw").val() == oldpassword){
		layer.msg('新密码不能与原密码一致!');
		return;
	}
	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "userpsw",
		async:false,
		data:datastring,
	 	dataType:"json",
	    success: function(msg) {    //数据提交成功时返回数据
	    	if(msg.status == "1"){
        		userSession.needupdatepsw = 0;
        	}else{
        		layer.msg(msg.desc);
        		return;
        	}
	    	layer.closeAll();   
	    	$("#oldpsw").val('');
	    	$("#newpsw").val('');
	    	$("#repsw").val('');
	    },
	    error : function(e){
	        alert(e.status);
	        alert(e.responseText);
	    }
	
	});
}

function sub_pswclear(){
	if(userSession.needupdatepsw != 0){
		user_logout();
	}
}

</script>

</body>
</html>